Imports System.Drawing
Namespace Drawing

  ''' <summary>
  ''' General bitmap helper methods.
  ''' </summary>
  ''' <remarks></remarks>
  Public NotInheritable Class BitmapHelper

    ''' <summary>
    ''' Converts a Bitmap to an Byte array.
    ''' </summary>
    ''' <param name="value"><see cref="Image">Bitmap</see> to convert.</param>
    ''' <returns><see cref="Byte">Byte</see> array.</returns>
    ''' <remarks></remarks>
    Public Shared Function ConvertToByteArray(ByVal value As Image) As Byte()

      If value Is Nothing Then
        Throw New ArgumentNullException("value")
      End If

      Dim bitmapBytes As Byte()

      Using stream As New System.IO.MemoryStream

        value.Save(stream, value.RawFormat)
        bitmapBytes = stream.ToArray

      End Using

      Return bitmapBytes

    End Function


    Private Sub New()
    End Sub
  End Class

End Namespace